package com.yzc.android.network.mock;

import android.content.Context;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * Created by yzc on 16/5/10.
 */
public class AssetsFileParser {
    public static final String UTF_8 = "UTF-8";
    private Context mContext;

    public AssetsFileParser(Context mContext) {
        this.mContext = mContext;
    }

    public String readJsonFile(String jsonFilePath) throws Exception {
        BufferedReader br = null;

        try {
            br = new BufferedReader(new InputStreamReader(
                    mContext.getAssets().open(
                            jsonFilePath), UTF_8));
            String line;
            StringBuilder text = new StringBuilder();

            while ((line = br.readLine()) != null) {
                text.append(line);
            }
            br.close();
            return text.toString();
        } finally {
            if (br != null) {
                br.close();
            }
        }
    }
}
